package com.open.basic.spi;

import com.open.basic.util.DateUtils;
import com.open.basic.util.FileUtils;
import lombok.extern.slf4j.Slf4j;


import java.io.File;
import java.io.IOException;


/**
 * @author: zm
 * @Date: 2025/9/20 22:32
 * @Version: V1.0
 * @description: |
 */
@Slf4j
public class DefaultFileManage implements BasicFileManage{

    private String path;

    private String appName;

    public DefaultFileManage(String path, String appName){
        this.path = path;
        this.appName = appName;
    }

    @Override
    public String uploadFile(final File file, String module) throws IOException {
        String fullPath = path + File.separator + appName + File.separator + module + File.separator + DateUtils.now(DateUtils.yyyyMM);
        String fileName = fullPath + File.separator + file.getName();
        log.debug("上传文件：{}", fileName);
        FileUtils.createDirs(fullPath);
        FileUtils.copyFile(file, new File(fileName));
        return fileName;
    }

    @Override
    public File downloadFile(final String fullPath) {
        return FileUtils.getFile(fullPath);
    }

    @Override
    public void deleteFile(final String fullPath) throws IOException {
        File file = new File(fullPath);
        FileUtils.deleteFile(file);
    }
}
